//
//  ST_CallRecordCell.swift
//  btvideo
//
//  Created by mac on 2021/1/18.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import UIKit

class ST_CallRecordCell: ST_DTChatCell {

    override func commonInit(){
    
        super.commonInit()
        
        self.contentView.addSubview(record_back_view)
        self.record_back_view.addSubview(call_type_image_view)
        
        self.record_back_view.addSubview(record_label)
        
    }
//    MARK: - properties
    fileprivate lazy var call_type_image_view:UIImageView = {
        let control = UIImageView()
        control.animationRepeatCount = 0
        control.animationDuration = 1
        return control
    }()
    
    fileprivate lazy var record_back_view:UIView = {
        let control = UIView()
        control.cornerRadius = 20
        control.backgroundColor = UIColor.init(hex: 0xF2F4F7)
        return control
    }()
    
    fileprivate lazy var record_label:UILabel = {
        let control = UILabel()
        control.textColor = UIColor.init(hex: 0x8290A5)!
        control.font = UIFont.systemFont(ofSize: 14)
        return control
    }()

    
    fileprivate lazy var voice_call_image = ST_ImageUtils.imageName("voice_call_icon")
    
    fileprivate lazy var video_call_image = ST_ImageUtils.imageName("video_call_icon")
    
    override var message: ST_DTChatMessage!{
        didSet{
            

            icon.sd_setImage(with: message.portraitUri.compress_image().url, for: UIControl.State.normal, completed: nil)
            
            if uuid != message.uuid{
                
                self.uuid = message.uuid
                
                guard let record = message.callRecord else{
                    return
                }
                
                call_type_image_view.image = record.agoraType == 1 ? voice_call_image : video_call_image
                
                record_label.text = record.labelStr
            }
        }
    }
}



//MARK: - LeftCell

class ST_CallRecordLeftCell: ST_CallRecordCell {
    
    override func commonInit() {
        super.commonInit()
        
        icon.snp.makeConstraints { (make) in
            make.width.height.equalTo(40)
            make.left.equalToSuperview().offset(15)
            make.top.equalToSuperview().offset(15)
        }
        
        record_back_view.snp.makeConstraints { (make) in
            make.height.equalTo(40)
            make.width.equalTo(115)
            make.left.equalTo(icon.snp.right).offset(10)
            make.top.equalTo(icon)
        }
        
        call_type_image_view.snp.makeConstraints { (make) in
            make.left.equalTo(record_back_view).offset(17)
            make.centerY.equalToSuperview()
            make.height.width.equalTo(20)
        }
        
        record_label.snp.makeConstraints { (make) in
            make.left.equalTo(call_type_image_view.snp.right).offset(5)
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-17)
        }
        
    }
    
}





//MARK: - RightCell

class ST_CallRecordRightCell: ST_CallRecordCell {
    
    override func commonInit() {
        super.commonInit()
        
        icon.removeFromSuperview()
        
        record_back_view.snp.makeConstraints { (make) in
            make.height.equalTo(40)
            make.right.equalToSuperview().offset(-15)
            make.top.equalToSuperview().offset(15)
        }
        
        call_type_image_view.snp.makeConstraints { (make) in
            make.right.equalTo(record_back_view).offset(-17)
            make.centerY.equalToSuperview()
            make.height.width.equalTo(20)
        }
        
        record_label.snp.makeConstraints { (make) in
            make.right.equalTo(call_type_image_view.snp.left).offset(-5)
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(17)
        }
    }
}
